

#ifndef __CE_MATERIALMANAGER_H__
#define __CE_MATERIALMANAGER_H__

#include <cegfx/iqf.h>
#include <cegfx/ceeffect.h>
#include <cegfx/ceexport.h>
#include <cegfx/cematerial.h>
#include <cegfx/cexml.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <list>
#include <string>

class CE_GFX_API ceMaterialManager : public iBase
{
	IQF_DECLARATION;
private:
	struct BaseData
	{
		char*		Name;
		char*		Filename;
	};

	struct TextureData : BaseData
	{
		LPDIRECT3DTEXTURE9	Texture;
	};

	struct EffectData : BaseData
	{
		ceEffect*	Effect;
	};

	struct MaterialData : BaseData
	{
		ceMaterial* Material;
	};


	std::list<TextureData>		textures;
	std::list<EffectData>			effects;
	std::list<MaterialData>	materials;

	void OpenData (ceXmlElement * element);
	void LoadColors (ceXmlElement* element, ceMaterial* material);
	void LoadMaps (ceXmlElement* element, ceMaterial* material);

	LPDIRECT3DDEVICE9 device;

public:
	ceMaterialManager (LPDIRECT3DDEVICE9 device);
	~ceMaterialManager ();

	bool LoadMaterial (const char* filename);
	void RegisterEffect (const char* filename, const char* effectname);

	bool HasEffect (const char* name);
	bool HasTexture (const char* name);

	ceMaterial* GetMaterial (const char* name);
	ceEffect* GetEffect (const char* name);
	LPDIRECT3DTEXTURE9 GetTexture (const char* name);
};


#endif /* ! __CE_MATERIALMANAGER_H__ */ 
